<!-- 题目一行组件 -->
<template>
  <div class="subject">
    <span>{{ num1 }}</span>
    <span>+</span>
    <span>{{ num2 }}</span>
    <span>=</span>
    <input type="number" v-model="result1" />
    <button @click="check">提交</button>
  </div>
</template>

<script>
export default {
  data() {
    return {
      num1: 0,
      num2: 0,
      result: 0,
      result1: "",
    };
  },
  mounted() {
    this.num1 = Math.floor(Math.random() * 10);
    this.num2 = Math.floor(Math.random() * 10);
    this.result = this.num1 + this.num2;
  },
  methods: {
    check() {
      if (this.result1 === "") {
        this.$emit("check", "未完成");
        return;
      }
      if (this.result1 == this.result) {
        this.$emit("check", "回答正确");
      } else {
        this.$emit("check", "回答错误");
      }
    },
  },
};
</script>

<style scoped>
.subject {
  margin: 5px;
  padding: 5px;
  font-size: 20px;
}
.subject span {
  display: inline-block;
  text-align: center;
  width: 20px;
}
.subject input {
  width: 50px;
  height: 20px;
}
</style>
